﻿using ProductSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProductSystem.BLL
{
    public class V_User_RoleBll
    {
        /// <summary>
        /// 用户角色对应列表
        /// </summary>
        /// <returns>用户角色对应列表</returns>
        public static List<V_User_ROle> GetList()
        {
            List<V_User_ROle> list;
            using (EntitiesModel dbContext = new EntitiesModel())
            {
                list = dbContext.V_User_ROles.Where(o => o.Status == 1).ToList();
            }
            return list;
        }


        /// <summary>
        /// 获取用户的角色名称
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="list">用户角色对应列表</param>
        /// <returns>角色名称</returns>
        public static string GetUserRoleName(int userId, List<V_User_ROle> list)
        {
            string userRoleName = string.Empty;
            List<V_User_ROle> tempList = list.Where(o => o.User_ID == userId).ToList();    //该用户的角色列表
            foreach (V_User_ROle userRole in tempList)
            {
                userRoleName += userRole.Role_Name + ",";
            }
            if (!string.IsNullOrEmpty(userRoleName))
            {
                userRoleName = userRoleName.Substring(0, userRoleName.Length - 1);
            }
            return userRoleName;
        }
    }
}
